
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>

<body>
<div class="container-login">
    <div class="container-pic">
        <!--        <img src="pic/computer.png" width="350px">-->
    </div>
    <div class="login-dialog">
        <h3>登陆</h3>
        <div class="row" >
            <span>用户名</span>
            <input type="text" name="userName" id="userName" class="form-control">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password" class="form-control">
        </div>
        <!-- 新增的用户类型选择框 -->
        <div class="row">
            <span>用户类型</span>
            <select class="form-control" name="userType" id="userType">
                <option value="normal" selected>普通用户</option>
                <option value="librarian">图书管理员</option>
            </select>
        </div>
        <!-- 登录/注册按钮 -->
        <div class="row" style="margin-top: 30px;">
            <div class="col-md-6">
                <button type="button" class="btn btn-info btn-lg btn-block" onclick="login()">登录</button>
            </div>
            <div class="col-md-6">
                <button type="button" class="btn btn-success btn-lg btn-block" onclick="location.href='register.html'">注册</button>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script>
    function login() {
        $.ajax({
            url:"/user/login",
            type:"post",
            data:{
                "userName":$("#userName").val(),
                "password":$("#password").val(),
                "userType":$("#userType").val()
            },
            success:function(result){
                if(result.status=="FAIL"){
                    alert("用户名或密码错误！");
                }

                if(result.data.userType=="librarian"){
                    //管理员
                    location.href = "book_list.html";
                }else if(result.data.userType=="normal"){
                    //普通用户
                    location.href = "book_list_normal.html";
                }else{
                    alert("用户名或密码错误！");
                }

            }
        });
    }
</script>
</body>
</html>